from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime

class NodeOut(BaseModel):
    id: int
    name: str
    host: str
    ssh_user: str
    ssh_port: int
    status: bool

    class Config:
        orm_mode = True

class CNameBase(BaseModel):
    domain: str
    ttl: Optional[int] = 30
    status: Optional[bool] = True

class CNameCreate(CNameBase):
    node_ids: List[int]  # 创建 CName 时关联的节点ID列表

class CNameUpdate(CNameBase):
    node_ids: Optional[List[int]] = None

class CNameOut(CNameBase):
    id: int
    created_at: datetime
    updated_at: datetime
    nodes: List[NodeOut] = []  # 带上节点信息

    class Config:
        orm_mode = True


